﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace CommunityToolkitMvvmDemo.Common
{
    public class WindowManager
    {
        static Dictionary<string,Type> _regWindow = new Dictionary<string,Type>();
        public static  void Register<T>(string name)
        {
            if (!_regWindow.ContainsKey(name))
            {
                _regWindow.Add(name, typeof(T));
            }
        }
        /// <summary>
        /// 打开子窗口
        /// </summary>
        /// <param name="name"></param>
        /// <param name="model"></param>
        public static void ShowDialog(string name,object model)
        {
            if (_regWindow.ContainsKey(name))
            {
                Type type = _regWindow[name];
                var win = (Window)Activator.CreateInstance(type);
                win.DataContext = model;
                win.ShowDialog();
            }
        }

    }
}
